package com.viphuli.http.handler;

import android.app.Activity;
import android.content.Intent;

import com.viphuli.common.AccessTokenKeeper;
import com.viphuli.fragment.AccountLoginFragment;
import com.viphuli.http.bean.page.AccountLoginPage;

/**
 * 登录
 * 
 * @author li.li
 *
 */
public class AccountLoginResponseHandler extends MyBaseHttpResponseHandler<AccountLoginFragment, AccountLoginPage> {

	@Override
	public void deal() {

		//存储用户信息
		String accessToken = page.getUser().getUid();
		String openId = page.getUser().getUid();
		String expiresTime = String.valueOf(Long.MAX_VALUE);

		AccessTokenKeeper tokenKeeper = new AccessTokenKeeper(accessToken, expiresTime, openId);
		AccessTokenKeeper.keepAccessToken(caller.getActivity(), tokenKeeper);
		
		setResultAndFinish();

	}
	
	/**
	 * 设置结果并结束
	 * @param localName
	 * @param address
	 */
	private void setResultAndFinish() {
		Intent intent = new Intent();
		caller.getActivity().setResult(Activity.RESULT_OK, intent);
		caller.getActivity().finish();
	}

}
